﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;


namespace XHCTMS.VIEW
{
    public partial class Checking : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
             if (!Page.IsPostBack)
            {               
                ViewState["TeachingId"] = Convert.ToInt32(Request.QueryString["teachingid"].ToString());
                GetView();                               
            }
        }
       
        // 提交考勤       
        protected void btnChecking_Click(object sender, EventArgs e)
        {
            
            for (int i = 0; i <= this.Checkinginfo.Items.Count - 1; i++)
            {
                Label lblCheckTeaId = (Label)Checkinginfo.Items[i].FindControl("lblCheckingTeaId");
                DropDownList DDLScore = (DropDownList)Checkinginfo.Items[i].FindControl("ddlScore");
                Label lblCheckStuId = (Label)Checkinginfo.Items[i].FindControl("lblCheckingStuId"); 
               
                MODEL.Checking checking = new MODEL.Checking();
                checking.CheckingTeachingId = Convert.ToInt32(lblCheckTeaId.Text);
                if (DDLScore.Text != string.Empty)
                {
                    checking.CheckingScore = ChangeScore(DDLScore.Text);
                    checking.CheckingReason = DDLScore.Text;
                }
                else
                {
                    checking.CheckingScore = 1;
                    checking.CheckingReason = "正常";
                }
                checking.CheckingStudentId = Convert.ToInt32(lblCheckStuId.Text);
                checking.CheckingCTime = DateTime.Now.ToLongTimeString()+" "+DateTime.Now.ToLongDateString();
                int result = new BLL.Checking().Add(checking);                
            }            
            GetView();
        }

        private double ChangeScore(string score)
        {
            double result = 0;
            switch (score)
            {
                case "正常":
                    result = 0;
                    break;
                case "迟到":
                    result = -0.5;
                    break;
                case "旷课":
                    result = -0.5;
                    break;
                case "事假":
                    result = -0.5;
                    break;
                case "病假":
                    result = -0.2;
                    break;
                default:
                    
                    break;
            }
            return result;
        }

        // 获取下拉框的值        
        private void GetView()
        {
            DataTable dt = new XHCTMS.BLL.Checking().View(Convert.ToInt32(ViewState["TeachingId"]) );
            this.Checkinginfo.DataSource = dt;
            Checkinginfo.DataBind();
        }
       
}
}